/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.himilco.ocana.gui.commun;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 *
 * @author oussema
 */
public class SessionCounterListener implements HttpSessionListener {

    private static int totalActiveSessions;
//    @EJB
//    SupervisorBO supervisorBO;
    @Override
    public void sessionCreated(HttpSessionEvent hse) {
        totalActiveSessions++;
        System.out.println("sessionCreated - add one session into counter");
//        final String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
//         System.out.println(""+currentUser);    
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//
//        Collection<? extends GrantedAuthority> roles = authentication.getAuthorities();
//        for (GrantedAuthority role : roles) {
//            System.out.println(""+role.getAuthority());                    
//            if (role.getAuthority().equals("operator")) {
//                supervisorBO.invokeUpdateTicket();
//            }
//        }        
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent hse) {
        totalActiveSessions--;
        System.out.println("sessionDestroyed - deduct one session from counter");
    }

//    @PreAuthorize("hasRole('operator')")
//    public void getForum(long id) {
//        final String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//
//        Collection<? extends GrantedAuthority> roles = authentication.getAuthorities();
//        for (GrantedAuthority role : roles) {
//            System.out.println(""+role.getAuthority());                    
//            if (role.getAuthority().equals("operator")) {
//                supervisorBO.invokeUpdateTicket();
//            }
//        }
//
//    }
}
